﻿using System.Collections.Generic;
using System.Linq;

namespace VirtualTournaments.Services.Tournaments
{
    public class TournamentsService
    {
        public static Tournament[] GetAllTournaments()
        {
            List<Tournament> result = new List<Tournament>();
            Data.DataMappers.TournamentsDataMapper.Instance.GetAll().ToList().ForEach(t => result.Add(Biz2DTO(t)));
            return result.ToArray();
        }

        public static Tournament[] GetTournamentsByName(string name)
        {
            List<Tournament> result = new List<Tournament>();
            Data.DataMappers.TournamentsDataMapper.Instance.GetByName(name).ToList().ForEach(t => result.Add(Biz2DTO(t)));
            return result.ToArray();
        }

        private static Tournament Biz2DTO(Biz.Tournaments.Tournament tournament)
        {
            return new Tournament() { Name = tournament.Name, Active = tournament.IsActive };
        }

        public static Tournament[] GetActiveTournaments()
        {
            List<Tournament> result = new List<Tournament>();
            Data.DataMappers.TournamentsDataMapper.Instance.GetActives().ToList().ForEach(t => result.Add(Biz2DTO(t)));
            return result.ToArray();
        }
    }
}
